//
//  ThreeCell.m
//  CellFactoryModel
//
//  Created by 向祖华 on 16/4/22.
//  Copyright © 2016年 向祖华. All rights reserved.
//

#import "ThreeCell.h"

static NSInteger cellHeight = 0;
@implementation ThreeCell

-(RootTableViewCell*)initWithDataModel:(DataModel*)model{
    self.backgroundColor = [UIColor greenColor];
    self.lable = [[UILabel alloc] initWithFrame:CGRectMake(10,10, 100, 30)];
    self.lable.text = model.title;
    [self addSubview:self.lable];
    //取到第一张图片，按第一张图片的标准给其他图片设置大小，保证显示时，三张图片平齐
    UIImage * image1 =[UIImage imageNamed:model.imageOneName];
    CGSize  size = CGSizeMake(kScreenW/3, ((kScreenW/3)/image1.size.width)*image1.size.height);
    CGPoint point;
    
    if ([model.title length] == 0) {
        self.lable.hidden = YES;
        point = CGPointMake(0, 10);
    } else {
        self.lable.hidden = NO;
        point = CGPointMake(0, 40);
    }
    self.imageVOne = [[UIImageView alloc] initWithFrame:CGRectMake(point.x, point.y, size.width, size.height)];
    self.imageVOne.image = [UIImage imageNamed:model.imageOneName];
    [self addSubview:self.imageVOne];
    self.imageVTwo = [[UIImageView alloc] initWithFrame:CGRectMake(point.x+kScreenW/3, point.y, size.width, size.height)];
    self.imageVTwo.image = [UIImage imageNamed:model.imageTwoName];
    [self addSubview:self.imageVTwo];
    self.imageVThree = [[UIImageView alloc] initWithFrame:CGRectMake(point.x+kScreenW*2/3, point.y, size.width, size.height)];
    self.imageVThree.image = [UIImage imageNamed:model.imageThreeName];
    [self addSubview:self.imageVThree];
    
    cellHeight = CGRectGetMaxY(self.imageVThree.frame);
    return self;
}

-(CGFloat)cellHeight{
    return cellHeight;
}

@end
